Repository navigation
Fix #532: "@: unbound variable" when terraform run with no arguments - #541
Open
marcleblanc2 wants to merge 3 commits into
Open
marcleblanc2 wants to merge 3 commits into
marcleblanc2 wants to merge 3 commits into
Conversation
…ash 3.2 when run with no arguments 0bd45d1 changed the argument loop in tfenv-exec() to `for _arg in "${@}"` to stop word-splitting arguments with spaces (tfutils#453). Under `set -u`, Bash 3.2 (macOS /bin/bash) treats an empty "$@" as an unbound variable, so running the shim with no arguments now aborts before terraform runs. zsh's bashcompinit invokes `complete -C` commands with no arguments, so every tab completion after `terraform` printed only this error. Use `for _arg; do`, which iterates the positional parameters without expanding "$@", so it neither word-splits nor trips `set -u` on any Bash version. Add test/test_exec.sh covering the shim with no arguments (under both `bash` and /bin/bash) and a -chdir path containing a space, and correct the for-loop guidance in AGENTS.md and bash.instructions.md. Amp-Thread-ID: https://ampcode.com/threads/T-01a0eee4-d46a-776d-9873-341f0d5f7fd2 Co-authored-by: Amp <amp@ampcode.com>
Author
|
Hey @Zordrak, is this project active and / or looking for maintainers? It's been a game changer to use. |
Borrowed from tfutils#539: a terraform 'version -json' case that checks arguments reach terraform independent of -chdir handling, and chmod +x to match the other test_*.sh files. Amp-Thread-ID: https://ampcode.com/threads/T-01a18edd-7c03-774f-890d-1da6f2ebc8c4 Co-authored-by: Amp <amp@ampcode.com>
terraform run with no arguments
Amp-Thread-ID: https://ampcode.com/threads/T-01a18edd-7c03-774f-890d-1da6f2ebc8c4 Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Running the
terraformshim with no arguments fails on macOS/bin/bash(Bash 3.2):Bash 3.2 treats
"${@}"as unbound underset -uwhen there are no arguments. 0bd45d1 (#453) introducedfor _arg in "${@}"to stop word-splitting arguments with spaces. zsh'sbashcompinitrunscomplete -Ccommands with no arguments, so on macOS every tab completion afterterraformhit this.Fix:
for _arg; do, which iterates the positional parameters without expanding"$@". Works on Bash 3.2 through 5 and keeps #453 fixed.Also updates the for-loop guidance in
AGENTS.mdand.github/instructions/bash.instructions.md, which recommended the form that caused this.Issue Link
Fixes #532
Testing
./test/run.shlocally; all suites pass exceptinstall_and_use,prerelease_filter,use_dash,use_latestallowed, which fail identically onmasteron this machine (Bad CPU type in executable: pre-1.0darwin_amd64builds on Apple Silicon without Rosetta)macos-latestandubuntu-latestwith this repo's unchangedtest.ymlrun on a fork (run 41146231609): all 16 suites pass, including the newtest_exec.sh. Note: fork PR runs on this repo currently die before any job starts ("workflow file issue"), so the checks here have not executed.test/test_exec.shbashand/bin/bash: reaches terraform usage, nounbound variable(fails onmaster)terraform version -json: arguments pass throughterraform '-chdir=chdir-dir/with space' version: argument is not word-split (Bug: Unquoted ${@:1} word-splits arguments with spaces in tfenv-exec.sh #453 regression guard)Platform tested: macOS 26 (arm64), Bash 3.2.57 and 5.x
Quality Checklist
AGENTS.md)